package org.example.app.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
 * 品类洞察结果实体类 - 符合实时数仓设计规范
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class CategoryInsightResult extends BaseDwsBean {
    
    // 业务主键
    private String categoryId;
    private String categoryName;
    
    // 层级维度
    private String parentCategoryId;
    private String parentCategoryName;
    private Integer categoryLevel;
    
    // 基础度量字段
    private Double totalSalesAmount;
    private Long totalSalesCount;
    private Long productCount;
    private Long brandCount;
    private Long shopCount;
    private Double avgPrice;
    private Double marketShare;
    
    // 属性分析字段
    private String topColor;
    private String topSize;
    private String topMaterial;
    private String topBrand;
    private Double colorConcentration;   // 颜色集中度
    private Double sizeConcentration;    // 尺寸集中度
    private Double materialConcentration; // 材质集中度
    private Double brandConcentration;   // 品牌集中度
    
    // 价格分析字段
    private Double minPrice;
    private Double maxPrice;
    private Double medianPrice;
    private Double priceStdDev;         // 价格标准差
    private String priceDistribution;   // 价格分布类型
    
    // 竞争分析字段
    private Integer competitorCount;     // 竞争对手数量
    private Double competitionIntensity; // 竞争激烈程度
    private String competitionLevel;     // 竞争等级：high/medium/low
    
    /**
     * 计算市场份额
     */
    public void calculateMarketShare(Double totalMarketSales) {
        if (totalMarketSales != null && totalMarketSales > 0 && totalSalesAmount != null) {
            this.marketShare = totalSalesAmount / totalMarketSales * 100;
        } else {
            this.marketShare = 0.0;
        }
    }
    
    /**
     * 计算平均价格
     */
    public void calculateAvgPrice() {
        if (totalSalesCount != null && totalSalesCount > 0 && totalSalesAmount != null) {
            this.avgPrice = totalSalesAmount / totalSalesCount;
        } else {
            this.avgPrice = 0.0;
        }
    }
    
    /**
     * 设置竞争等级
     */
    public void setCompetitionLevel() {
        if (competitionIntensity != null) {
            if (competitionIntensity >= 0.8) {
                this.competitionLevel = "high";
            } else if (competitionIntensity >= 0.5) {
                this.competitionLevel = "medium";
            } else {
                this.competitionLevel = "low";
            }
        } else {
            this.competitionLevel = "unknown";
        }
    }
}